package com.itheima.service.impl.activemq;

import com.itheima.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;

/**
 * ClassName: MessageServiceActivemqImpl
 * Description:
 * Date: 2023/03/16 PM 10:21:53
 * <p>
 * project: springboot
 * package: com.itheima.service.impl.activemq
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
// @Service
public class MessageServiceActivemqImpl implements MessageService {

    @Autowired
    private JmsMessagingTemplate messagingTemplate;


    /**
     * 发送消息
     *
     * @param id {@link String} 订单 id
     */
    @Override
    public void sendMessage(String id) {
        System.out.println("待发送短信的订单已纳入处理队列，id: " + id);
        messagingTemplate.convertAndSend("order.queue.id", id);
    }

    /**
     * 发送消息
     *
     * @return {@link String}
     */
    @Override
    public String doMessage() {
        String id = messagingTemplate.receiveAndConvert("order.queue.id", String.class);
        System.out.println("已完成短信发送业务，id: " + id);
        return id;
    }
}
